﻿using System;
using System.Data;
using System.Windows.Forms;
using UniMana.Utils.Data;
using DevExpress.XtraGrid;
using DevExpress.Utils;
using UniMana.Data;

namespace UniMana.Win.Training
{
    public partial class FrmScore_ShowSubjectClassID : DevExpress.XtraEditors.XtraForm
    {
        public string m_sClassID = "";
        private DBMain m_Score = new DBMain();
        private int m_row = 0;
        public FrmScore_ShowSubjectClassID()
        {
            InitializeComponent();
        }
        public FrmScore_ShowSubjectClassID(string ID, bool check)
        {
            InitializeComponent();
            grvSubjectClass.FocusedRowHandle = GridControl.AutoFilterRowHandle;
            grvSubjectClass.FocusedColumn = grvSubjectClass.Columns[1];
            grvSubjectClass.SetFocusedRowCellValue(grvSubjectClass.Columns[1], ID);
            DataTable dt = new DataTable();
            if (check == true)
            {
                dt = m_Score.m_DCReadOnly.Training_Subject_Classes.GetLikeSubjectClassList(ID).ToDataTable();
            }
            else
            {
                dt = m_Score.m_DCReadOnly.Training_Classes.GetLikeClassList(ID).ToDataTable();
            }
            gctSubjectClass.DataSource = dt;
            m_row = dt.Rows.Count;
        }
        public bool Check()
        {
            if (m_row > 0)
                return true;
            else
                return false;
        }
        private void grvSubjectClass_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            int rowIndex = e.RowHandle;
            if (rowIndex >= 0)
            {
                rowIndex++;
                e.Info.DisplayText = rowIndex.ToString();
            }
        }
        private void grvSubjectClass_DoubleClick(object sender, EventArgs e)
        {
            //MessageBox.Show(grvSubjectClass.GetFocusedRowCellValue(grvSubjectClass.Columns[1]).ToString());
            m_sClassID = grvSubjectClass.GetFocusedRowCellValue(grvSubjectClass.Columns[1]).ToString();
            this.Close();
        }
        private void gctSubjectClass_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                m_sClassID = grvSubjectClass.GetFocusedRowCellValue(grvSubjectClass.Columns[1]).ToString();
                this.Close();
            }
        }
        private void FrmScore_ShowSubjectClassID_Load(object sender, EventArgs e)
        {
            gctSubjectClass.ForceInitialize();
            grvSubjectClass.FocusedRowHandle = GridControl.AutoFilterRowHandle;
            grvSubjectClass.FocusedColumn = grvSubjectClass.Columns[1];
            grvSubjectClass.ShowEditor();
        }
        private void toolTip_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
        {
            if (grvSubjectClass.FocusedRowHandle == GridControl.AutoFilterRowHandle)
            {
                if (grvSubjectClass.FocusedColumn == grvSubjectClass.Columns[1])
                {
                    e.Info = new ToolTipControlInfo(e.SelectedControl.Focused, "Info", "Content");
                    //e.Info = new ToolTipControlInfo(e.SelectedControl.Name, "Content", "Info");
                    SuperToolTip SuperTip = new SuperToolTip();
                    SuperToolTipSetupArgs args = new SuperToolTipSetupArgs();
                    args.Title.Text = "*Hướng dẫn:";
                    args.Contents.Text = "Nhấn phím 'End' để tiếp tục nhập!";
                    SuperTip.Setup(args);
                    (e.Info as ToolTipControlInfo).SuperTip = SuperTip;
                }
            }
        }
    }
}